// pages/user/submit/submit.js
import { Request } from "../../../utils/request.js"
var request = new Request()
Page({
  data: {
    textareaValue: '',
    contentLength: 0,
    changeColor: true,
    usageRate: 5,
    functionRate: 5,
    panelRate: 5,
  },
  rateChange: function (e) {
    var str = e.target.id
    if (str == "usageRate") {
      this.setData({
        usageRate: e.detail
      })
    } else if (str == "functionRate") {
      this.setData({
        functionRate: e.detail
      })
    } else {
      this.setData({
        panelRate: e.detail
      })
    }
  },
  textareaInput(e) {
    if (e.detail.value.length > 300) {
      this.setData({
        changeColor: false
      })
    } else {
      this.setData({
        changeColor: true,
      })
    }
    this.setData({
      textareaValue: e.detail.value,
      contentLength: e.detail.value.length
    })
  },

  /**
   * 提交建议内容和三个评分标准
   */
  submitBtn() {
    var that = this
    console.log(this.data.contentLength)
    if (this.data.contentLength == 0) {
      wx.showModal({
        title: '提交失败',
        content: '您的建议对我们很重要哦~',
        showCancel: false,
      })
    } else {
      var openId = wx.getStorageSync('openId')
      request.post(
        "advice",
        {
          usageRate: this.data.usageRate,
          functionRate: this.data.functionRate,
          panelRate: this.data.functionRate,
          content: this.data.textareaValue,
          openId: openId

        },
        (res) => {
          console.log(res)
          if (res.statusCode == 200) {
            wx.showToast({
              title: "提交成功",
              icon: 'success',
              duration: 2000
            })
          }
        }
      )
    }
  }
})